home *** CD-ROM | disk | FTP | other *** search
/ Delphi Programmer's Power Pack / Delphi Volume 1.iso / s_to_z / t_rex10 / trexdmo1.dpr < prev    next >
Text File  |  1996-09-15  |  4KB  |  88 lines

  1. program Trexdmo1;
  2.  
  3. {
  4. $Log:   W:/users/prodigy/prodig~1/archive/trex/trexdmo1.dpv  $
  5.    
  6.       Rev 1.0   07 Apr 1996 18:30:38   PaulK
  7.    Work in progress on demos
  8. }
  9.  
  10. uses
  11.   Forms,
  12.   Trexdm01 in 'TREXDM01.PAS' {Form1};
  13.  
  14. {$R *.RES}
  15. {$R TREXDEMO.RES}
  16.  
  17. {This demo program scans a Pascal program and reports on the
  18.  number of lines that consist entirely of comments. For example,
  19.  this comment would count as 5 comment lines. But the comment in
  20.  the Uses clause has program text outside the comment on the same
  21.  line and so would not count.}
  22.  
  23. {The regular expressions used in this program are elaborate. If
  24.  the symbolics are new to you, you may find them overwhelming at
  25.  first, despite the walkthrough below. If so, first check out the
  26.  regular expression tutorial in the helpfile, and then one of the
  27.  other demo programs, before examining this one in detail.}
  28.  
  29. {The program uses 5 regular expressions to determine
  30.  commenthood. Every line is tested against each one in sequence;
  31.  but a match on one causes the other tests to be skipped. The
  32.  program causes this behaviour by calling SeekEoln after a match.
  33.  T-Rex's normal behaviour is to match every MatchPattern.}
  34.  
  35. {Here is a walkthrough of the regular expressions you will find
  36.  in the MatchPattern property. There's no room for comments there.}
  37.  
  38. (* 1: ^ *({[^}]*} * )+$
  39.    Starting at beginning of line "^", there may be 0 or more
  40.    spaces " *" and then a brace "{" [ignore parenthesis for the
  41.    moment; discussed below]. This can be followed by any number
  42.    of nonbrace characters inside the comment "[^}]*" but a
  43.    single closing brace "}" ends the comment. After that, there
  44.    can be zero or more spaces " *". This pattern can be repeated
  45.    more than once (....)+ before the end of line
  46.    "$" is reached. In other words, the comment starts and ends
  47.    on a single line (or several of them all start and end on
  48.    the same line), and there is nothing but spaces before and
  49.    after it/them on that line. [There is a spurious space before
  50.    ")+$" in the expression as shown here to avoid closing this
  51.    Pascal comment prematurely.]                                 *)
  52.  
  53. (* 2: ^ *{[^}]*$
  54.    Starting at beginning of line "^", there may be 0 or more
  55.    spaces " *" and then a brace "{". This can be followed by
  56.    any number of nonbrace characters inside the comment
  57.    "[^}]*". The end of line "$" is reached before
  58.    a closing brace is found. In other words, the comment starts
  59.    on this line, but does not end on it, and there is nothing but
  60.    spaces before the comment.                                   *)
  61.  
  62. (* 3: {[^}]*$
  63.    A comment begins "{" on this line, but does not end. There must
  64.    be some non-comment stuff before the left brace, else pattern
  65.    2 would have matched. So this is the start of a multiline
  66.    comment, but does not itself add to the comment linecount,
  67.    because this line does not consist solely of comments.       *)
  68.  
  69. (* 4: } *$
  70.    A comment ends "}" on this line, and there are only 0 or more
  71.    spaces " *" before the end of line "$" is reached. The comment
  72.    did not begin on this line (else 1-3 would have matched).    *)
  73.  
  74. (* 5: }
  75.    A comment ends "}" on this line, but 4 did not match so there
  76.    must have been some code after the comment.                  *)
  77.  
  78. {This is a demo program, not a serious application. The following
  79.  are not handled:
  80.  1. Comments of the form (* *).
  81.  2. Comments that contain left braces.                           }
  82.  
  83.  
  84. begin
  85.   Application.CreateForm(TForm1, Form1);
  86.   Application.Run;
  87. end.
  88.